﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

/// <summary>
/// 移动端控制器输入，支持基本的按钮
/// </summary>
public class UIMobileInput : MonoBehaviour
{

    public static UIMobileInput Instance;
    /// <summary>
    /// 启用加速中
    /// </summary>
    /// <value></value>
    public static bool IsAccelerate { get; private set; }
    public static bool IsMoving { get; private set; }
    public static bool autoLockInRange = true;

    public static bool IsMobile  => Application.isMobilePlatform;
    public static Vector2 MoveDirection;
    public ActionButton accelButton;
    public Joystick joystick;

    private void Awake()
    {
        Instance = this;
    }

    private void OnEnable()
    {

    }

    private void OnDisable()
    {
        MoveDirection = Vector3.zero;
        IsMoving = false;
    }

    // Update is called once per frame
    void Update()
    {
        if (joystick)
        {
            if (joystick.IsDraging)
            {
                IsMoving = true;
                MoveDirection = joystick.Velocity;
            }
            else
            {
                IsMoving = false;
            }
        }

        if (accelButton)
        {
            IsAccelerate = accelButton.isTouchDown;
        }
        else
        {
            IsAccelerate = false;
        }

    }
}
